package study.cv.opencv.task;

import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import study.cv.opencv.support.utils.WinUtils;

/**
 * https://blog.csdn.net/sinat_29950703/article/details/107978687
 */
@Slf4j
public class Ocr_Task {

    private String inputFile = "d:/image/ocr/test_01.jpg";
    private String outputFile = "d:/image/ocr/test.jpg";

    @Before
    public void init() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    @Test
    public void test() {
        //
        Mat src = Imgcodecs.imread(inputFile);
        //
        Mat copy = new Mat();
        src.copyTo(copy);

        //------ 预处理 ------
        Imgproc.cvtColor(copy, copy, Imgproc.COLOR_BGR2GRAY);
        Imgproc.GaussianBlur(copy, copy, new Size(5, 5), 0);
        //边缘检测
        Imgproc.Canny(copy, copy, 75, 200);
        WinUtils.imShow(copy);

        Imgcodecs.imwrite(outputFile, copy);
    }
}
